package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemHomeServicePatentBinding;
import com.sgb.kjwl.model.entity.enterprise.PatentEntity;
import com.sgb.kjwl.utils.PointUtils;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class HomePatentAdapter extends BaseRecycleAdapter<PatentEntity> {

    public HomePatentAdapter(Context context, List<PatentEntity> datas) {
        super(context, R.layout.item_home_service_patent, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, PatentEntity patentEntity) {
        ItemHomeServicePatentBinding binding = (ItemHomeServicePatentBinding) holder.getmBinding();
        binding.setViewModel(patentEntity);
        TextView tv_tag = holder.getItem().findViewById(R.id.tv_item_intel_prop_publish);
        switch (patentEntity.getPublishType()) {
            case 0://个人
                tv_tag.setText("个人");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 1://企业
                tv_tag.setText("企业");
                tv_tag.setBackgroundResource(R.drawable.shape_radius_1_solid_bule);
                break;
            case 2://团队
                tv_tag.setText("团队");
                tv_tag.setBackgroundResource(R.drawable.ractangle_radius_1_solid_yellow);
                break;
            default:
                tv_tag.setVisibility(View.GONE);
                break;
        }
        binding.price.setText(patentEntity.getPrice() != -1 ? "¥" + PointUtils.price(patentEntity.getPrice()) : "议价");

        ImageView roundImageView = holder.getItem().findViewById(R.id.logo_view);

        if (patentEntity.getImg() != null && !patentEntity.getImg().equals("")) {
            Glide.with(context).load(patentEntity.getImg()).into(roundImageView);
        } else {
            switch (patentEntity.getCategoryName()){
                case "发明专利":
                    Glide.with(context).load(R.mipmap.qiyefuwu_module_famingzhuanli_for_patent_publish).into(roundImageView);
                    break;
                case "实用新型":
                    Glide.with(context).load(R.mipmap.shiyongxinxing_patent_publish).into(roundImageView);
                    break;
                case "外观设计":
                    Glide.with(context).load(R.mipmap.waiguansheji_patent_publish).into(roundImageView);
                    break;
            }
        }
    }
}
